﻿using Hangfire;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Zocono.WCS.HangfireHost.Hangfire
{
    // HFJobActivatorScope.cs
    public class HFJobActivatorScope : JobActivatorScope
    {
        private IServiceScope _serviceScope;
        public HFJobActivatorScope(IServiceScope serviceScope)
        {
            if (serviceScope == null) throw new ArgumentNullException(nameof(serviceScope));
            _serviceScope = serviceScope;
        }
        public override object Resolve(Type type)
        {
            return _serviceScope.ServiceProvider.GetService(type);
        }
        public override void DisposeScope()
        {
            _serviceScope.Dispose();
        }
    }
}
